package com.fandou.airobot.ui.alarm;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

import com.bumptech.glide.Glide;
import com.fandou.airobot.R;
import com.lxj.xpopup.core.CenterPopupView;

/**
 * @author Jm
 * @date 2020/6/29 17:54
 * @description 闹钟或者倒计时提示dialog
 */
public class AlarmRemindPop extends CenterPopupView implements LifecycleObserver {

    private Context mContext;

    private String title;

    private String remark;

    public AlarmRemindPop(@NonNull Context context, String title, String remark) {
        super(context);
        this.mContext = context;
        if (context instanceof AppCompatActivity) {
            ((AppCompatActivity) context).getLifecycle().addObserver(this);
        }
        this.title = title;
        this.remark = remark;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.alarm_remind_pop;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        ((TextView) findViewById(R.id.tvTitle)).setText(title);
        ((TextView) findViewById(R.id.tvMessage)).setText(remark);
        ImageView ivAlert = findViewById(R.id.ivAlert);
        Glide.with(getContext()).load(R.drawable.ic_alarm_remind).into(ivAlert);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    @Override
    protected void onDismiss() {
        super.onDismiss();
        if (mContext instanceof AppCompatActivity) {
            ((AppCompatActivity) mContext).finish();
        }
    }
}
